fix(form-core): Prevent synchronous validators from returning Promises#1987
Conversation
🦋 Changeset detectedLatest commit: 6b927d2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Passing an asynchronous function to a synchronous validator (i.e.: `onBlur`, `onChange`, `onDynamic`, `onSubmit`) is a bit of a foot-gun given that it does not produce any typescript errors, but it also results in the form/field validation function running after the core validation logic. To prevent this, update the types for these validator functions on both `FormApi` and `FieldApi` to prevent passing a function that returns a `Promise`.
5924423 to
2198362
Compare
|
View your CI Pipeline Execution ↗ for commit ec84898
☁️ Nx Cloud last updated this comment at |
|
Just pushed an update that should address the lint issue, sorry about that! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1987 +/- ##
==========================================
+ Coverage 90.35% 90.76% +0.41%
==========================================
Files 38 59 +21
Lines 1752 2209 +457
Branches 444 555 +111
==========================================
+ Hits 1583 2005 +422
- Misses 149 183 +34
- Partials 20 21 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Just wanted to follow up to see if there's anything that's needed for this to be considered for acceptance. Thanks! 😄 |
|
Core concept looks good to me. I'm mostly waiting to check up on some things like instantiation count and testing some surface-level alternatives. Should be done by the end of the week. |
|
@LeCarbonator Just wanted to follow up to see if there's anything else needed here. I can rebase my branch, just let me know! |
crutchcorn
left a comment
There was a problem hiding this comment.
This is awesome. Sorry for missing it on my end. Got @LeCarbonator's approval privately as well. Thank you for this!
# Conflicts: # packages/form-core/src/FieldApi.ts
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR enforces a type-level constraint preventing synchronous validators in TanStack Form from returning Promises. A new ChangesSync Validator Promise Rejection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Awesome, thanks for getting this merged! |
🎯 Changes
Passing an asynchronous function to a synchronous validator (i.e.:
onBlur,onChange,onDynamic,onSubmit) is a bit of a foot-gun given that it does not produce any typescript errors, but it also results in the form/field validation function running after the core validation logic.This updates the types for these validator functions on both FormApi and FieldApi to prevent passing a function that returns a Promise.
✅ Checklist
pnpm test:pr.🚀 Release Impact
Summary by CodeRabbit